package com.handpay.zztong.hp;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.config.ZZTConstant;

public class RechargeMainActivity extends ZZTongActivity {

	private List<ItemConfig> mItems;
	private ChargeValue mChargeValue = ChargeValue.type_50;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		setContentView(R.layout.layout_recharge);
		super.onCreate(savedInstanceState);
		initView();
	}

	private void initView() {
		mItems = new ArrayList<ItemConfig>();
		mItems.add(new ItemConfig(R.id.radio_one, ChargeValue.type_50));
		mItems.add(new ItemConfig(R.id.radio_two, ChargeValue.type_100));
		mItems.add(new ItemConfig(R.id.radio_three, ChargeValue.type_200));
		mItems.add(new ItemConfig(R.id.radio_four, ChargeValue.type_300));
		mItems.add(new ItemConfig(R.id.radio_five, ChargeValue.type_500));
		setTextValue();

	}

	@Override
	public ActionBar getActivityActionBar() {
		TextView tv = new TextView(this);
        tv.setText("充值记录");
        tv.setTextSize(14);
        tv.setTextColor(this.getResources().getColor(R.color.backgournd_white_color));
        tv.setPadding(0, 0, 30, 0);
        tv.setOnClickListener(CommonUtils.createNoQuickResponseViewListener(ZZTConstant.NO_RESPONSE_CLICK_TIME, new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            }
        }));
		return new ActionBar(getString(R.string.phone_charge), true,tv);
	}

	private enum ChargeValue {
		type_50, type_100, type_200, type_300, type_500
	}

	private class ItemConfig {
		private int mResId;

		public ItemConfig(int mResId, final ChargeValue chargeValue) {
			super();

			this.mResId = mResId;
			getRadioButton().setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View view) {
					int id = view.getId();
					SelectRadio(id);
					mChargeValue = chargeValue;
					setTextValue();
				}
			});
		}

		public int getmResId() {
			return mResId;
		}

		public RadioButton getRadioButton() {
			return (RadioButton) findViewById(mResId);
		}

	}

	public void SelectRadio(int id) {
		for (ItemConfig item : mItems) {
			RadioButton radioButton = item.getRadioButton();
			if (id == item.getmResId()) {
				radioButton.setChecked(true);
			} else {
				radioButton.setChecked(false);

			}

		}
	}

	private int getChargeRMB() {
		int charge = 0;
		if (mChargeValue == ChargeValue.type_50) {
			charge = 50;
		} else if (mChargeValue == ChargeValue.type_100) {
			charge = 100;
		} else if (mChargeValue == ChargeValue.type_200) {
			charge = 200;
		} else if (mChargeValue == ChargeValue.type_300) {
			charge = 300;
		} else if (mChargeValue == ChargeValue.type_500) {
			charge = 500;
		}

		return charge;
	}

	public void setTextValue() {
		((TextView) (findViewById(R.id.tv_pay_amount))).setText(String
				.valueOf(getChargeRMB()) + "元");
	}
}
